package com.xy.user.service;


import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import com.xy.user.domain.XyMenu;
import com.xy.user.persistence.XyMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 菜单栏
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class XyMenuService extends BaseService<XyMenu> {
    @Autowired
    private XyMenuMapper xymenuMapper;

    @Autowired
    public void setBaseMapper(XyMenuMapper xymenuMapper) {
        this.baseMapper = xymenuMapper;
    }

    public List<Map<String,Object>> getListParentId(Map<String, Object> param) {
        return xymenuMapper.listParentId(param);
    }

    public void checkEntity(XyMenu xymenu) throws ClassCheckException {
        if(xymenu.getMenuId()!=null&&xymenu.getMenuId().length()>19){
            throw new ClassCheckException("菜单栏菜单ID不能超过19个字符");
        }
        if(xymenu.getName()!=null&&xymenu.getName().length()>19){
            throw new ClassCheckException("菜单栏菜单名称不能超过19个字符");
        }
        if(xymenu.getNameEn()!=null&&xymenu.getNameEn().length()>19){
            throw new ClassCheckException("菜单栏菜单标识不能超过19个字符");
        }
        if(xymenu.getUrl()!=null&&xymenu.getUrl().length()>19){
            throw new ClassCheckException("菜单栏链接不能超过50个字符");
        }
        if(xymenu.getParentId()!=null&&xymenu.getParentId().length()>19){
            throw new ClassCheckException("菜单栏上级菜单不能超过19个字符");
        }
    }
    public void checkListEntity(List<XyMenu> listXyMenu) throws ClassCheckException {

        for (XyMenu xymenu : listXyMenu) {
            checkEntity(xymenu);
        }

    }

    public List<XyMenu> queryByRoleIdIn(List<String> roleIdList) {
        if(roleIdList==null||roleIdList.size()==0){
            return new ArrayList<XyMenu>();
        }
        return xymenuMapper.queryByRoleIdIn(roleIdList);
    }

    public List<XyMenu> getAllList() {
        return xymenuMapper.getAllList();
    }

    public List<XyMenu> queryByUserId(String userId) {
        return xymenuMapper.queryByUserId(userId);
    }

    public List<XyMenu> queryByAll() {
        return xymenuMapper.queryByAll();
    }

    public List<Map<String, Object>> getList(Map<String, Object> param) {
        return baseMapper.getList(param);
    }
}
